<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="../css/materialize.css">
  <style>
    .btn.lowercase{
      text-transform: lowercase;
    }
    #submit{
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="row">
      <button class="waves-effect btn lowercase grey" data-name="google" id=baidu>baidu</button>
      <button class="waves-effect btn lowercase" data-name="baidu" id=google>google</button>
    </div>
    <div class="row center">
      <div class="input-field col s6 offset-s2 input-wraper">
        <input type="text" id=getMe><label for="getMe">请输入</label>
      </div>
      <a class="waves-effect btn col s2" id="submit">
        <i class="material-icons left">search</i>搜索
      </a>
    </div>
  </div>
  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.slim.min.js"></script>
  <script src="../js/materialize.js"></script>
  <script>
    $(document).ready(function(){
      let obj = {
        name: 'google'
      };
      $('.lowercase').on('click', function () {
        $(this).addClass('grey').siblings().removeClass('grey');
      });
      $('#getMe').on('keyup', function (event) {
        if(event.keyCode === 13){
          event.preventDefault();
          $('#submit').click()
        }
      });
      
      $('#submit').on('click', function(){
        let href;
        let { name } = obj;
        let res = $('#getMe').val();
        if(res !== ''){
          if(name === 'baidu'){
            href = `https://www.baidu.com/s?wd=${res}`
          }else {
            href = `https://www.google.com/search?q=${res}`
          }
          window.open(href, '_self')
        }
      })
    });
  </script>
</body>
</html>